#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<vector>
using namespace std;
const long long N = 1e6 + 10;
int n, m;
typedef long long LL;

LL sum_col[N];
LL sum_row[N];
int main()
{

    scanf("%d %d", &n, &m);
    LL  arr[n][m];
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            scanf("%lld", &arr[i][j]);

            sum_row[i] += arr[i][j];

        }

    }
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            sum_col[i] += arr[j][i];
        }
    }


    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
  
            arr[i][j] = sum_row[i] + sum_col[j] - arr[i][j];

            cout << arr[i][j] << " ";
        }

        cout << endl;
    }
    return 0;
}